<template>
  <div class="login-container">
    <h3 class="title" style="font-weight: 400;">智能会议室管理系<span>统</span></h3>
    <el-card class="login-card">
      <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
        <img src="../../assets/icons/迅慧达.png" alt="logo" class="logo">
        <el-form-item prop="id">
          <span class="svg-container">
            <img src="../../assets/icons/用户名.png" alt="user" class="icon">
            <!-- <svg-icon icon-class="user" /> -->
          </span>
          <el-input v-model="loginForm.id" name="id" type="text" auto-complete="on" placeholder="请输入工号" />
        </el-form-item>
        <el-form-item prop="password">
          <span class="svg-container">
            <img src="../../assets/icons/密码.png" alt="password" class="icon">
            <!-- <svg-icon icon-class="password" /> -->
          </span>
          <el-input
            :type="pwdType"
            v-model="loginForm.password"
            name="password"
            auto-complete="on"
            placeholder="请输入密码"
            @keyup.enter.native="handleLogin" />
          <span class="show-pwd" @click="showPwd">
            <svg-icon icon-class="eye" />
          </span>
        </el-form-item>
        <el-form-item class="btnItem">
          <el-button :loading="loading" type="primary" style="width:100%;" @click.native.prevent="handleLogin">
            登<span>录</span>
          </el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>

export default {
  name: 'Login',
  data() {
    const validatePass = (rule, value, callback) => {
      if (value.length < 4) {
        callback(new Error('密码不能小于4位'))
      } else {
        callback()
      }
    }

    return {
      loginForm: {
        id: 'root',
        password: 'root'
      },
      loginRules: {
        id: [{ required: true, trigger: 'blur' }],
        password: [{ required: true, trigger: 'blur', validator: validatePass }]
      },
      loading: false,
      pwdType: 'password'
    }
  },
  methods: {
    showPwd() {
      if (this.pwdType === 'password') {
        this.pwdType = ''
      } else {
        this.pwdType = 'password'
      }
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          this.$store.dispatch('Login', this.loginForm).then(() => {
            this.loading = false
            this.$router.push({ path: '/' })
          }).catch(() => {
            this.loading = false
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
$bg:#2d3a4b;
$light_gray:#eee;

/* reset element-ui css */
.login-container {
  .el-card__body {
    width: 100%;
  }
  .el-input {
    display: inline-block;
    height: 47px;
    width: 75%;
    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: #000;
      font-size: 18px;
      height: 47px;
      &:-webkit-autofill {
        -webkit-box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: #fff !important;
      }
    }
  }
  .el-form-item {
    border: 3px solid rgba(38, 127, 218, 0.9);
    background: rgba(255, 255, 255, 0.9);
    border-radius: 5px;
    color: #454545;
    margin-bottom: 26px;
  }
}

</style>

<style rel="stylesheet/scss" lang="scss" scoped>
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;
.login-container {
  position: fixed;
  height: 100%;
  width: 100%;
  background: url('../../assets/icons/管理系统.png') no-repeat;
  background-size: 100% 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  .title {
      font-size: 3em;
      font-weight: 400;
      color: #000;
      margin: 0px auto 20px auto;
      text-align: center;
      font-weight: bold;
      letter-spacing: .2em;
      span {
        letter-spacing: 0;
      }
    }
  .login-card {
      width: 620px;
      max-width: 100%;
      border: 5px solid #2C7EB5;
      background-color: rgba(229, 238, 244, .9);
      margin: 20px auto;
      padding: 30px;
    .login-form {
      width: 70%;
      margin: 0 auto;
      .logo {
        margin: 0 auto 40px;
        width: 250px;
        display: block;
      }
    }
    .btnItem {
      border: none;
      button {
        font-size: 18px;
        letter-spacing: 1em;
        span {
        letter-spacing: 0;
        }
      }
    }
    .tips {
      font-size: 14px;
      color: #fff;
      margin-bottom: 10px;
      span {
        &:first-of-type {
          margin-right: 16px;
        }
      }
    }
    .svg-container {
      padding: 0 5px 0 15px;
      color: $dark_gray;
      vertical-align: middle;
      width: 50px;
      height: 100%;
      line-height: 100%;
      display: inline-block;
      .icon {
        width: 100%;
      }
    }
    .show-pwd {
      position: absolute;
      right: 10px;
      top: 7px;
      font-size: 16px;
      color: $dark_gray;
      cursor: pointer;
      user-select: none;
    }
  }
}
</style>
